package lv.ante.xwiki.filters;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

public class MimeTypeResponseWrapper extends HttpServletResponseWrapper {

       private String delimiter;
       private String mime;

       public MimeTypeResponseWrapper(HttpServletResponse response,
                       String delimiter, String mime) {
               super(response);                
               this.delimiter = delimiter;
               this.mime = mime;
//              System.out.println("MimeTypeResponseWrapper.mime == " + mime);
//              System.out.println("MimeTypeResponseWrapper.delimiter == " + delimiter);

       }

       public void setContentType(String arg) {
               super.setContentType(mime + ";charset=UTF-8");
       }

       public PrintWriter getWriter() {
               try {
                       PrintWriter out = super.getWriter();
                       SkippingFilterWriter filterOut = new SkippingFilterWriter(out, delimiter);
                       return new PrintWriter(filterOut);
               } catch (IOException e) {
                       e.printStackTrace();
               }
               return null;
       }
}

